package com.xjmall.common;

import com.google.common.collect.Sets;

import java.util.Set;

/**
 * Created by An on 2017/5/6.
 */
public class Const {

    // 当前登录用户
    public static final String CURRENT_USER = "currentUser";
    // 用户名
    public static final String USERNAME = "username";
    // Email
    public static final String EMAIL = "email";

    // 商品分类状态
    public interface CategoryStatus {
        int CATEGORY_USE = 1; // 启用
        int CATEGORY_STOP = 0; // 停用
    }
    // 用户角色
    public interface Role {
        int ROLE_CUSTOMER = 0; // 普通用户
        int ROLE_ADMIN = 1; // 管理员
    }
    // 评论类别
    public interface CommentType {
        int COMMENT_GOOD = 10; // 好评
        int COMMENT_NORMAL = 20; // 中评
        int COMMENT_POOR = 30; // 差评
    }
    // 产品列表的排序规则
    public interface ProductListOrderBy {
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price_asc", "price_desc");
    }
    // 购物车
    public interface Cart {
        int CHECKED = 1; // 购物车被选中的状态
        int UN_CHECKED = 0; // 购物车未被选中的状态

        String LIMIT_NUM_FAIL = "LIMIT_NUM_FAIL";
        String LIMIT_NUM_SUCCESS = "LIMIT_NUM_SUCCESS";
    }
    // 支付宝回调
    public interface AlipayCallback {
        String WAIT_BUYER_PAY = "WAIT_BUYER_PAY";
        String TRADE_STATUS_TRADE_SUCCESS = "TRADE_SUCCESS";
        String RESPONSE_SUCCESS = "success";
        String RESPONSE_FAILED = "failed";
    }

    // 用户登录校验状态
    public enum UserLoginCheckStatus {
        USERNAME_NOT_FOUND(11, "用户名不存在"),
        USERNAME_NOT_NULL(12, "用户名不能为空"),
        PASSWORD_NOT_NULL(13, "密码不能为空"),
        PASSWORD_ERROR(14, "密码错误"),
        NOT_ADMIN(15, "不是管理员，不能登录");

        private int code;
        private String value;

        UserLoginCheckStatus(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public int getCode() {
            return code;
        }
        public String getValue() {
            return value;
        }
    }

    //产品在售状态
    public enum ProductStatusEnum {
        ON_SALE(1, "在售"),
        OFF_SALE(2, "下架");

        private String value;
        private int code;

        ProductStatusEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }
    }
    // 订单状态
    public enum OrderStatusEnum {
        CANCELED(0, "已取消"),
        NO_PAY(10, "未付款"),
        PAID(20, "已付款"),
        SHIPPED(40, "已发货"),
        ORDER_SUCCESS(50, "订单完成"),
        ORDER_CLOSE(60, "订单关闭");

        OrderStatusEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }
        private String value;
        private int code;

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public static OrderStatusEnum codeOf(int code) {
            for (OrderStatusEnum orderStatusEnum : values()) {
                if (orderStatusEnum.getCode() == code) {
                    return orderStatusEnum;
                }
            }
            throw new RuntimeException("没有找到对应的枚举");
        }
    }
    // 支付方式
    public enum PayPlatformEnum {
        ALIPAY(1, "支付宝");

        PayPlatformEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }
        private String value;
        private int code;

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }
    }
    //支付类型
    public enum PaymentTypeEnum {
        ONLINE_PAY(1, "在线支付");

        PaymentTypeEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }
        private String value;
        private int code;

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public static PaymentTypeEnum codeOf(int code) {
            for (PaymentTypeEnum paymentTypeEnum : values()) {
                if (paymentTypeEnum.getCode() == code) {
                    return paymentTypeEnum;
                }
            }
            throw new RuntimeException("没有找到对应的枚举");
        }
    }
}
